/* -----------------------------------------------------------------------
 * unittest1.c
 * Unit test for getCost() function in dominion.c
 *
 * -----------------------------------------------------------------------
 */

#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"

//declaration for function to convert card no. to card name
char* getCard(int cardNo); 

//declaration for unit testing function
int checkCard(int testCard, int testReturn, int* passCount, int* failCount);

int main() {
    int i; //loop counter
    int passCount = 0;
    int failCount = 0;
    printf("\nTesting GetCosts().\n\n");
    printf ("Testing all valid cards:\n\n");
    
    //test all cards
    for (i= curse; i<= treasure_map; i++){


    printf("Testing card %s:\n", getCard(i));

        checkCard(i, getCost(i), &passCount, &failCount);
    }

    //test boundary cases
    printf("Testing boundary cases:\n\n");
    printf("Testing (curse - 1):\n");
    printf("getCost(curse - 1): ");
    checkCard(curse - 1, getCost(curse - 1), &passCount, &failCount);

    printf("Testing (treasure_map + 1):\n");
    printf("getCost(treasure_map + 1): ");
    checkCard(treasure_map + 1, getCost(treasure_map + 1), &passCount, &failCount);

    if (failCount == 0){
        printf("All tests passed!\n");
    }
    else{
        printf("%d tests passed and %d tests failed,", passCount, failCount);
    }



    return 0;
}

/**
 * unit testing function for getCost
 */
int checkCard(int testCard, int testReturn, int* passCount, int* failCount){
    if (testCard == curse){
    	printf("getCost(%s): %d  ", getCard(testCard), testReturn);
    	printf("Expected: 0\n");
    	if (testReturn == 0){
            printf("TEST PASSED\n\n");
            (*passCount)++;
        }
        else{
            printf("TEST FAILED\n\n");
            (*failCount)++;
        }
    }
    else if (testCard == estate){
    	printf("getCost(%s): %d  ", getCard(testCard), testReturn);
    	printf("Expected: 2\n");
    	if (testReturn == 2){
            printf("TEST PASSED");
            (*passCount)++;
        }
        else{
            printf("TEST FAILED");
            (*failCount)++;
        }
    }
    else if (testCard == duchy){
    	printf("getCost(%s): %d  ", getCard(testCard), testReturn);
    	printf("Expected: 5\n");
        if (testReturn == 5){
            printf("TEST PASSED\n\n");
            (*passCount)++;
        }
        else{
            printf("TEST FAILED\n\n");
            (*failCount)++;
        }
    }
    else if (testCard == province){
    	printf("getCost(%s): %d  ", getCard(testCard), testReturn);
    	printf("Expected: 8\n");
        if (testReturn == 8){
            printf("TEST PASSED\n\n");
            (*passCount)++;
        }
        else{
            printf("TEST FAILED\n\n");
            (*failCount)++;
        }
    }
    else if (testCard == copper){
    	printf("getCost(%s): %d  ", getCard(testCard), testReturn);
    	printf("Expected: 0\n");
        if (testReturn == 0){
            printf("TEST PASSED\n\n");
            (*passCount)++;
        }
        else{
            printf("TEST FAILED\n\n");
            (*failCount)++;
        }
    }
    else if (testCard == silver){
    	printf("getCost(%s): %d  ", getCard(testCard), testReturn);
    	printf("Expected: 3\n");
        if (testReturn == 3){
            printf("TEST PASSED\n\n");
            (*passCount)++;
        }
        else{
            printf("TEST FAILED\n\n");
            (*failCount)++;
        }
    }
    else if (testCard == gold){
    	printf("getCost(%s): %d  ", getCard(testCard), testReturn);
    	printf("Expected: 6\n");
        if (testReturn == 6){
            printf("TEST PASSED\n\n");
            (*passCount)++;
        }
        else{
            printf("TEST FAILED\n\n");
            (*failCount)++;
        }
    }
    else if (testCard == adventurer){
    	printf("getCost(%s): %d  ", getCard(testCard), testReturn);
    	printf("Expected: 6\n");
        if (testReturn == 6){
            printf("TEST PASSED\n\n");
            (*passCount)++;
        }
        else{
            printf("TEST FAILED\n\n");
            (*failCount)++;
        }
    }
    else if (testCard == council_room){
    	printf("getCost(%s): %d  ", getCard(testCard), testReturn);
    	printf("Expected: 5\n");
        if (testReturn == 5){
            printf("TEST PASSED\n\n");
            (*passCount)++;
        }
        else{
            printf("TEST FAILED\n\n");
            (*failCount)++;
        }
    }
    else if (testCard == feast){
    	printf("getCost(%s): %d  ", getCard(testCard), testReturn);
    	printf("Expected: 4\n");
        if (testReturn == 4){
            printf("TEST PASSED\n\n");
            (*passCount)++;
        }
        else{
            printf("TEST FAILED\n\n");
            (*failCount)++;
        }
    }
    else if (testCard == gardens){
    	printf("getCost(%s): %d  ", getCard(testCard), testReturn);
    	printf("Expected: 4\n");
        if (testReturn == 4){
            printf("TEST PASSED\n\n");
            (*passCount)++;
        }
        else{
            printf("TEST FAILED\n\n");
            (*failCount)++;
        }
    }
    else if (testCard == mine){
    	printf("getCost(%s): %d  ", getCard(testCard), testReturn);
    	printf("Expected: 5\n");
        if (testReturn == 5){
            printf("TEST PASSED\n\n");
            (*passCount)++;
        }
        else{
            printf("TEST FAILED\n\n");
            (*failCount)++;
        }
    }
    else if (testCard == remodel){
    	printf("getCost(%s): %d  ", getCard(testCard), testReturn);
    	printf("Expected: 4\n");
        if (testReturn == 4){
            printf("TEST PASSED\n\n");
            (*passCount)++;
        }
        else{
            printf("TEST FAILED\n\n");
            (*failCount)++;
        }
    }
    else if (testCard == smithy){
    	printf("getCost(%s): %d  ", getCard(testCard), testReturn);
    	printf("Expected: 4\n");
        if (testReturn == 4){
            printf("TEST PASSED\n\n");
            (*passCount)++;
        }
        else{
            printf("TEST FAILED\n\n");
            (*failCount)++;
        }
    }
    else if (testCard == village){
    	printf("getCost(%s): %d  ", getCard(testCard), testReturn);
    	printf("Expected: 3\n");
        if (testReturn == 3){
            printf("TEST PASSED\n\n");
            (*passCount)++;
        }
        else{
            printf("TEST FAILED\n\n");
            (*failCount)++;
        }
    }
    else if (testCard == baron){
    	printf("getCost(%s): %d  ", getCard(testCard), testReturn);
    	printf("Expected: 4\n");
        if (testReturn == 4){
            printf("TEST PASSED\n\n");
            (*passCount)++;
        }
        else{
            printf("TEST FAILED\n\n");
            (*failCount)++;
        }    }
    else if (testCard == great_hall){
    	printf("getCost(%s): %d  ", getCard(testCard), testReturn);
    	printf("Expected: 3\n");
        if (testReturn == 3){
            printf("TEST PASSED\n\n");
            (*passCount)++;
        }
        else{
            printf("TEST FAILED\n\n");
            (*failCount)++;
        }
    }
    else if (testCard == minion){
    	printf("getCost(%s): %d  ", getCard(testCard), testReturn);
    	printf("Expected: 5\n");
        if (testReturn == 5){
            printf("TEST PASSED\n\n");
            (*passCount)++;
        }
        else{
            printf("TEST FAILED\n\n");
            (*failCount)++;
        }
    }
    else if (testCard == steward){
    	printf("getCost(%s): %d  ", getCard(testCard), testReturn);
    	printf("Expected: 3\n");
        if (testReturn == 3){
            printf("TEST PASSED\n\n");
            (*passCount)++;
        }
        else{
            printf("TEST FAILED\n\n");
            (*failCount)++;
        }
    }
    else if (testCard == tribute){
    	printf("getCost(%s): %d  ", getCard(testCard), testReturn);
    	printf("Expected: 5\n");
        if (testReturn == 5){
            printf("TEST PASSED\n\n");
            (*passCount)++;
        }
        else{
            printf("TEST FAILED\n\n");
            (*failCount)++;
        }
    }
    else if (testCard == ambassador){
    	printf("getCost(%s): %d  ", getCard(testCard), testReturn);
    	printf("Expected: 3\n");
        if (testReturn == 3){
            printf("TEST PASSED\n\n");
            (*passCount)++;
        }
        else{
            printf("TEST FAILED\n\n");
            (*failCount)++;
        }
    }
    else if (testCard == cutpurse){
    	printf("getCost(%s): %d  ", getCard(testCard), testReturn);
    	printf("Expected: 4\n");
        if (testReturn == 4){
            printf("TEST PASSED\n\n");
            (*passCount)++;
        }
        else{
            printf("TEST FAILED\n\n");
            (*failCount)++;
        }
    }
    else if (testCard == embargo){
    	printf("getCost(%s): %d  ", getCard(testCard), testReturn);
    	printf("Expected: 2\n");
        if (testReturn == 2){
            printf("TEST PASSED\n\n");
            (*passCount)++;
        }
        else{
            printf("TEST FAILED\n\n");
            (*failCount)++;
        }
    }
    else if (testCard == outpost){
    	printf("getCost(%s): %d  ", getCard(testCard), testReturn);
    	printf("Expected: 5\n");
        if (testReturn == 5){
            printf("TEST PASSED\n\n");
            (*passCount)++;
        }
        else{
            printf("TEST FAILED\n\n");
            (*failCount)++;
        }
    }
    else if (testCard == salvager){
    	printf("getCost(%s): %d  ", getCard(testCard), testReturn);
    	printf("Expected: 4\n");
        if (testReturn == 4){
            printf("TEST PASSED\n\n");
            (*passCount)++;
        }
        else{
            printf("TEST FAILED\n\n");
            (*failCount)++;
        }
    }
    else if (testCard == sea_hag){
    	printf("getCost(%s): %d  ", getCard(testCard), testReturn);
    	printf("Expected: 4\n");
        if (testReturn == 4){
            printf("TEST PASSED\n\n");
            (*passCount)++;
        }
        else{
            printf("TEST FAILED\n\n");
            (*failCount)++;
        }
    }
    else if (testCard == treasure_map){
    	printf("getCost(%s): %d  ", getCard(testCard), testReturn);
    	printf("Expected: 4\n");
        if (testReturn == 4){
            printf("TEST PASSED\n\n");
            (*passCount)++;
        }
        else{
            printf("TEST FAILED\n\n");
            (*failCount)++;
        }
    }
    else {
    	printf("%d  ", testReturn);
    	printf("Expected: -1\n");
        if (testReturn == -1){
            printf("TEST PASSED\n\n");
            (*passCount)++;
        }
        else{
            printf("TEST FAILED\n\n");
            (*failCount)++;
        }
    }
    return 0;
}

char* getCard(int cardNo){
    if (cardNo == curse){
        return "curse";
    }
    if (cardNo == estate){
        return "estate";
    }
    if (cardNo == duchy){
        return "duchy";
    }
    if (cardNo == province){
        return "province";
    }
    if (cardNo == copper){
        return "copper";
    }
    if (cardNo == silver){
        return "silver";
    }
    if (cardNo == gold){
        return "gold";
    }
    if (cardNo == adventurer){
        return "adventurer";
    }
    if (cardNo == council_room){
        return "council_room";
    }
    if (cardNo == feast){
        return "feast";
    }
    if (cardNo == gardens){
        return "gardens";
    }
    if (cardNo == mine){
        return "mine";
    }
    if (cardNo == remodel){
        return "remodel";
    }
    if (cardNo == smithy){
        return "smithy";
    }
    if (cardNo == village){
        return "village";
    }
    if (cardNo == baron){
        return "baron";
    }
    if (cardNo == great_hall){
        return "great_hall";
    }
    if (cardNo == minion){
        return "minion";
    }
    if (cardNo == steward){
        return "steward";
    }
    if (cardNo == tribute){
        return "tribute";
    }
    if (cardNo == ambassador){
        return "ambassador";
    }
    if (cardNo == cutpurse){
        return "cutpurse";
    }
    if (cardNo == embargo){
        return "embargo";
    }
    if (cardNo == outpost){
        return "outpost";
    }
    if (cardNo == salvager){
        return "salvager";
    }
    if (cardNo == sea_hag){
        return "sea_hag";
    }
    if (cardNo == treasure_map){
        return "treasure_map";
    }
    return "fail";
}


